use glass::Reflect;
use rand::random_bool;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use serde_json::Value;

pub mod number;
pub mod text;

pub trait Generator: Reflect + Default + Serialize + DeserializeOwned {
    fn generate(&self) -> Value;
}

#[derive(Debug, Default, Reflect, Serialize, Deserialize)]
pub struct BoolGenerator {
    #[name("布尔值")]
    pub value: Option<bool>,
}

impl Generator for BoolGenerator {
    fn generate(&self) -> Value {
        Value::Bool(self.value.unwrap_or(random_bool(1.0 / 3.0)))
    }
}
